<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\FirmMessage;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class FirmMessageController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new FirmMessage(['user:id,avatar,nickname']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user.avatar','用户头像')->image('',80,80);
            $grid->column('user.nickname','用户昵称');
            $grid->column('name');
            $grid->column('sex')
                ->using([1 => '男',2 =>'女',0 =>'未知']);
            $grid->column('content');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->disableCreateButton();
            $grid->disableActions();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->like('user.nickname','用户昵称')
                      ->width(3);
                $filter->equal('sex','用户昵称')
                       ->select([1 => '男',2 =>'女',0 =>'未知'])
                       ->width(3);

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FirmMessage(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('name');
            $show->field('sex');
            $show->field('content');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

}
